set proc to sospro
set proc to boxproc

CLOS DATA
dr1='N:'
dr2='Q:'

f1='dlv_PHAR.dbf'
F4='NEW_PAT.DBF'
SELE 1
SET EXCLU OFF
USE &DR1&F1
GO TOP
DO WHILE .NOT. EOF()
   IF DATE_DELV<DATE()-365
      IF REC_LOCK(0)
         DELE
      ENDIF
      UNLOCK
   ENDIF
   SKIP
ENDDO
IF NET_USE('&DR1&F1',.T.,'1',10)
   PACK
ENDIF
SET EXCLU OFF
USE

SELE 1
SET EXCLU OFF
USE &DR1&F4
GO TOP
DO WHILE .NOT. EOF()
   IF DATE_L_VIS<DATE()-30
      IF REC_LOCK(0)
         DELE
      ENDIF
      UNLOCK
   ENDIF
   SKIP
ENDDO

IF NET_USE('&DR1&F4',.T.,'1',10)
   PACK
ENDIF
SET EXCLU OFF
USE

f3='drug_ent.dbf'
f4='disp_ent.dbf'

SELE 1
SET EXCLU OFF
use &dr1&f3
GO TOP
DO WHILE .NOT. EOF()
   IF ENTRY_DATE<DATE()-365
      IF REC_LOCK(0)
         DELE
      ENDIF
      UNLOCK
   ENDIF
   SKIP
ENDDO
IF NET_USE('&DR1&F3',.T.,'1',10)
   PACK
ENDIF
SET EXCLU OFF
USE


SELE 1
SET EXCLU OFF
use &dr1&f4
GO TOP
DO WHILE .NOT. EOF()
   IF ENTRY_DATE<DATE()-365
      IF REC_LOCK(0)
         DELE
      ENDIF
      UNLOCK
   ENDIF
   SKIP
ENDDO
IF NET_USE('&DR1&F4',.T.,'1',10)
   PACK
ENDIF
SET EXCLU OFF
USE

dr1='N:'
dr2='Q:'
f1='drugs.dbf'
f2='dispos.dbf'
f3='company.dbf'
f4='supplier.dbf'

SELE 1
SET EXCLU OFF
use &dr1&f1
GO TOP
DO WHILE .NOT. EOF()
   IF REC_LOCK(0)
      REPL ST_BOM_SEL WITH ST_ACT_SEL
      REPL ST_BOM_BUY WITH ST_ACT_BUY
   ENDIF
   UNLOCK
   SKIP
ENDDO

if fil_lock(0)
   copy to &dr2&f1
endif
unlock
SET EXCLU OFF
USE

SELE 1
SET EXCLU OFF
use &dr1&f2
GO TOP
DO WHILE .NOT. EOF()
   IF REC_LOCK(0)
      REPL ST_BOM_SEL WITH ST_ACT_SEL
      REPL ST_BOM_BUY WITH ST_ACT_BUY
   ENDIF
   UNLOCK
   SKIP
ENDDO
if fil_lock(0)
   copy to &dr2&f2
endif
unlock
SET EXCLU OFF
USE

SELE 1
SET EXCLU OFF
use &dr1&f3
if fil_lock(0)
   copy to &dr2&f3
endif
unlock
SET EXCLU OFF
USE

SELE 1
SET EXCLU OFF
use &dr1&f4
if fil_lock(0)
   copy to &dr2&f4
endif
unlock
SET EXCLU OFF
USE
DO EOMPCPDB
DO EOMPCPMM
DO EOMPZPDB
DO EOMPINIT
do eompdldb
RETURN

